from database import get_db_cursor

def check_tables():
    with get_db_cursor() as cursor:
        cursor.execute('SHOW TABLES')
        tables = cursor.fetchall()
        print("数据库中的表:")
        for table in tables:
            # 表名可能在第一个元素中
            if isinstance(table, dict):
                # 如果结果是字典形式
                table_name = list(table.values())[0]
            else:
                # 如果结果是元组形式
                table_name = table[0] if len(table) > 0 else str(table)
            print(f"- {table_name}")
            
        # 特别检查community_posts表
        cursor.execute("SHOW TABLES LIKE 'community_posts'")
        community_posts_exists = cursor.fetchone() is not None
        print(f"\n特别检查: community_posts表{'存在' if community_posts_exists else '不存在'}")
        
        # 特别检查posts表
        cursor.execute("SHOW TABLES LIKE 'posts'")
        posts_exists = cursor.fetchone() is not None
        print(f"特别检查: posts表{'存在' if posts_exists else '不存在'}")
        
        # 查看post_likes表结构
        try:
            cursor.execute("DESCRIBE post_likes")
            columns = cursor.fetchall()
            print("\npost_likes表结构:")
            for column in columns:
                print(f"- {column}")
        except Exception as e:
            print(f"\n无法获取post_likes表结构: {str(e)}")

if __name__ == "__main__":
    check_tables() 